package com.inspur.edp.team.rest;


import com.inspur.edp.team.PaasTeamMemberService;
import com.inspur.edp.team.dto.TeamMember;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;
import io.iec.edp.caf.sysmanager.api.data.user.User;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * 开发团队成员管理restful接口
 */
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class TeamMemberController {

    private PaasTeamMemberService paasTeamMemberService = SpringBeanUtils.getBean(PaasTeamMemberService.class);

    /**
     * 添加成员
     *
     * @param teamMember
     * @
     */
    @POST
    @Path(value = "/addmember/{teamId}")
    public void addMember(@PathParam("teamId") String teamId, TeamMember teamMember) {
        paasTeamMemberService.addMember(teamId, teamMember);
    }


    /**
     * 移除成员
     *
     * @param teamId
     * @param userId
     * @
     */
    @DELETE
    @Path(value = "/removemember/{teamId}/{userId}")
    public void removeMember(@PathParam("teamId") String teamId, @PathParam("userId") String userId) {
        paasTeamMemberService.removeMember(teamId, userId);
    }


    /**
     * 编辑成员
     *
     * @param teamId
     * @param teamMember
     */
    @POST
    @Path(value = "/updatemember/{teamId}")
    public void updateMember(TeamMember teamMember,@PathParam("teamId") String teamId) {
        paasTeamMemberService.updateMember(teamMember, teamId);
    }

    /**
     * 成员列表
     *
     * @return
     * @
     */
    @GET
    @Path(value = "/memberlist/{teamId}")
    public List<TeamMember> getMemberListByTeamId(@PathParam("teamId") String teamId) {
        paasTeamMemberService.accessPermissioncheck(teamId);
        return paasTeamMemberService.getMemberListByTeamId(teamId);
    }



    @GET
    @Path(value = "/role/{teamId}")
    public TeamMember getMemberByTeamId(@PathParam("teamId") String teamId){
        return paasTeamMemberService.getMemberByTeamId(teamId);
    }

    /**
     * 邀请用户-用户名过滤查询
     *
     * @param codeOrName 用户名称过滤
     * @auth liuzhi
     * @return
     */
    @GET
    @Path(value = "/{codeOrName}")
    public List<User> checkUsers(@PathParam("codeOrName") String codeOrName) {
        return paasTeamMemberService.checkUserRes(codeOrName);
    }

}
